package chen.web.util.ubb;

import java.io.PrintStream;

import chen.web.util.ubb.standard.AlignTag;
import chen.web.util.ubb.standard.BTag;
import chen.web.util.ubb.standard.BackColorTag;
import chen.web.util.ubb.standard.BanTag;
import chen.web.util.ubb.standard.ColorTag;
import chen.web.util.ubb.standard.EmotionTag;
import chen.web.util.ubb.standard.FontTag;
import chen.web.util.ubb.standard.HtmlTag;
import chen.web.util.ubb.standard.ITag;
import chen.web.util.ubb.standard.ImgTag;
import chen.web.util.ubb.standard.STag;
import chen.web.util.ubb.standard.SizeTag;
import chen.web.util.ubb.standard.TableTag;
import chen.web.util.ubb.standard.TdTag;
import chen.web.util.ubb.standard.TrTag;
import chen.web.util.ubb.standard.UTag;
import chen.web.util.ubb.standard.UrlTag;

public class Testing {

	public static void main(String[] args){
		UbbParser parser = new UbbParser(new StandardEventHandler(factory));
		String ubb = "[img]http://fdsfsdafasf.com/fdsfasd/fdsaf.gif[/img]";
		PrintStream out = System.out;
		out.println(parser.parse(ubb).toHtml());
	}
	
	private static long testPerformance(int count){
		UbbParser standardParser = new UbbParser(new StandardEventHandler(factory));
		String ubb = "[img]http://fdsfsdafasf.com/fdsfasd/fdsaf.gif[/img][img]http://fdsfsdafasf.com/fdsfasd/fdsaf.gif[/img][img]http://fdsfsdafasf.com/fdsfasd/fdsaf.gif[/img][img]http://fdsfsdafasf.com/fdsfasd/fdsaf.gif[/img][img]http://fdsfsdafasf.com/fdsfasd/fdsaf.gif[/img][img]http://fdsfsdafasf.com/fdsfasd/fdsaf.gif[/img][img]http://fdsfsdafasf.com/fdsfasd/fdsaf.gif[/img][img]http://fdsfsdafasf.com/fdsfasd/fdsaf.gif[/img][img]http://fdsfsdafasf.com/fdsfasd/fdsaf.gif[/img]";
		long begin = System.currentTimeMillis();
		for(int i=0; i<count; i++){
			standardParser.parse(ubb).toHtml();	
		}
		return System.currentTimeMillis() - begin;
	}
	
	
	//标准的标签工厂包含所有标签
	private static TagFactory factory = new TagFactory();
	
	private static BTag b = new BTag();
	private static UTag u = new UTag();
	private static ITag i = new ITag();
	private static STag s = new STag();
	private static ImgTag img = new ImgTag();
	private static FontTag font = new FontTag();
	private static SizeTag size = new SizeTag();
	private static ColorTag color = new ColorTag();
	private static UrlTag url = new UrlTag();
	private static AlignTag align = new AlignTag();
	private static BackColorTag back = new BackColorTag();
	private static TableTag table = new TableTag();
	private static TrTag tr = new TrTag();
	private static TdTag td = new TdTag();
	private static EmotionTag emot = new EmotionTag();
	private static BanTag ban = new BanTag();
	private static HtmlTag html = new HtmlTag();
	
	static{
		url.setBlank(true);
		emot.setUrlRegex("http://xxx.com/emot/?/?.gif");
		factory.register(b,u,i,s,font,size,color,back,img,url,align,table,tr,td,emot,ban,html);
	}
}
